#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


enum day_t { HOUR, MINUTE, SECOND };

typedef struct Date {
  char a;
  enum day_t b;
  unsigned long long c;
  char d;
  int e;
  void *f;
  short g;
} Date;

long fun(int n) {
  int i;
  long s = 0;
  for (i = 0; i <= n; i++)
    s = s + i * i;
  return s;
}

int desc_sort(const int *arr, int len) {
  int i = 0, j = 0;
  for (i = 0; i < len; i++) {
    int low = 0, high = i - 1, mid = -1;
    while (low <= high) {
      mid = low + (high - low) / 2;
      if (arr[mid] > arr[i]) {
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }
    for (j = i - 1; j >= low; j--) {
      arr[j + 1] = arr[j]; // const错误，不能更改
    }
    arr[low] = arr[i];
  }
}

int my_odd_and_even_sort(int *arr, int len) {
  int i = 0;
  int *back_arr = NULL;
  int head = 0, tail = len;
  desc_sort(arr, len);
  back_arr = (int *)malloc(sizeof(int) * len);
  if (back_arr == NULL) {
    printf("malloc buffer error size: %d\n", sizeof(int) * len);
    return -1;
  }
  for (i = 0; i < len; i++) {
    if (arr[i] & 1) {
      // odd
      back_arr[head++] = arr[i];
    } else {
      back_arr[tail--] = arr[i];
    }
  }
  memcpy(arr, back_arr, strlen(arr));
  back_arr = NULL;
  return 0;
}

void main() {
  int i = 0;
  for (i = 1; i++ < 4;)
    ;
  printf("%d \n", i);
  Date date[2][10];

  printf("结构提长度：%d\n", sizeof(Date));

  printf("Date date[1][5]; = %p", &date[1][5]);
  printf("\n\n");
  int i2 = 0, Num[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  while (i2 < 3) {
    printf("%d ", Num[i][2 - i]);
    i2++;
  }

  int i3 = 0, len = 0;
  int arr[] = {49, 38, 65, 97, 76, 13, 27, 49, 78, 34, 12, 64, 1};
  len = sizeof(arr) / sizeof(int);
  my_odd_and_even_sort(arr, len);
  for (i3 = 0; i3 < len; i3++) {
    printf("arr[%d]: %d \n", i, arr[i]);
  }
}
